/*
 * @Description: * aip
 * @Date: 2021-01-06 22:12:34
 * @LastEditTime: 2021-04-01 21:02:39
 * @Author: Ji YingHao
 * @FilePath: /nuxt-app/api/index.js
 */

// import Vue from 'vue'

//  const API = {
//     // 分类
//     category: "/api/front/category"
//  }

// var comsys = {

//     install(Vue) {

//         Vue.prototype.$api = API;

//     }

// }

// Vue.use(comsys);


import request from '@/plugins/service'

const apis = {};

/* 获取分类 */ 
apis.category = (params) => {  return request({ url: '/api/front/category', method: 'get', params: params })};

/* 
    商品列表
    cid 分类id
    keyword 搜索关键字
    limit 每页数量
    news 是否新品
    page 页码
*/
apis.products = (params) => { return request({ url: '/api/front/products', method: 'get', params: params }) };

/* 商品详情 */
apis.detail = (id,params) => { return request({ url: `/api/front/product/detail/${id}`, method: 'get', params: params }) };


/* 首页产品的轮播图和产品信息 */
apis.groomList = (type, params) => { return request({ url: `/api/front/groom/list/${type}`, method: 'get', params: params }) };

/* 添加收藏产品 */
apis.collectAdd = (data) => {
    return request({
        url: '/api/front/collect/add',
        method: 'post',
        data: data
    })
}

/* 登录 */
apis.login = (data) => {
    return request({
        url: '/api/front/login',
        method: 'post',
        data: data
    })
}

/* 注册 */
apis.register = (data) => {
    return request({
        url: '/api/front/register',
        method: 'post',
        data: data
    })
}



apis.logout = (params) => { return request({ url: `/api/front/logout`, method: 'get', params: params }) };

/* 获取商品下载 */
apis.download = (params) => { return request({ url: `/api/front/product/download`, method: 'get', params: params }) };


/* 会员列表 */
apis.levelList = (params) => { return request({ url: `/api/front/user/level/grade`, method: 'get', params: params }) };


/* 用户登录信息 */
apis.userinfo = (params) => { return request({ url: `/api/front/userinfo`, method: 'get', params: params }) };


/* 登录信息 */
apis.user = (params) => { return request({ url: `/api/front/user`, method: 'get', params: params }) };

/* 登录信息 */
apis.user = (params) => { return request({ url: `/api/front/user`, method: 'get', params: params }) };


//保存cookie
//参数：cookie名,cookie值,有效时长(单位：天)
apis.saveCookie = (cookieName, cookieValue, cookieDates) => {
    var d = new Date();
    d.setDate(d.getDate() + cookieDates);
    document.cookie = cookieName + "=" + cookieValue + ";expires=" + d.toGMTString();
}

apis.getCookie = (cookieName)=>{
    var cookieStr = unescape(document.cookie);
    var arr = cookieStr.split("; ");
    var cookieValue = "";
    for (var i = 0; i < arr.length; i++) {
        var temp = arr[i].split("=");
        if (temp[0] == cookieName) {
            cookieValue = temp[1];
            break;
        }
    }
    return cookieValue;
}

// 当前登录用户信息


/*
apis.login = (data) => {
    return request({
        url: '/user/login',
        method: 'post',
        data: data
    })
}

apis.getUser = (params) => {
    return request({
        url: '/user/getUser',
        method: 'get',
        params: params
    })
}

*/

export default apis;